# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/30 下午4:09
 @Author  : tgy
 
"""
import time
import threading
import pickle

class DownCount:

    def __init__(self,n):
        ...
        self.n = n
        self.thread = threading.Thread(target=self.run)
        self.thread.daemon = False

    def start(self):
        if not self.thread:
            return
        self.thread.start()

    def run(self):

        if not self.n:
            return
        while self.n != 0:
            print(self.n)
            self.n -= 1
            time.sleep(1)

    def __setstate__(self, state):
        self.__init__(state)

    def __getstate__(self):
        return self.n

    def __repr__(self):
        return f'{self.__class__.__name__}[n = {self.n}]'


if __name__ == '__main__':
    ...
    dc = DownCount(5)
    print(dc)
    # dc.start()
    p_dc = pickle.dumps(dc)
    print(p_dc)
    dc_l = pickle.loads(p_dc)
    dc_l.start()